﻿/*
* author: xxxgggyyy
* date	: 2022-10-31
* desc	: BPT的内部节点
*/
#ifndef BPT_INNER_NODE_H
#define BPT_INNER_NODE_H

#include "bpt_node.h"

class BPTInnerNode : public BPTNode {
	friend class BPTree;
	friend class BPTNode;
private:
	//unsigned long* keys;
	BPTNode** nodes;
	int branchs;

protected:
	BPTInnerNode(int branchs);
	~BPTInnerNode();

	void insert(int, unsigned long, BPTNode*, bool);
	void insert_first(unsigned long key, BPTNode*, BPTNode*);
	void print();
	BPTInnerNode* split(unsigned long&);
	bool spilled();
	bool remove(unsigned long);
	void __remove(int, bool);
	bool concealed();
	bool concealed(int);
	unsigned long borrow(BPTNode*, unsigned long, bool);
	void append(BPTNode*, unsigned long);
	bool contain(unsigned long);

	/*序列化格式说明-按字节顺序
	* sizeof(int)			: 序列化长度
	* 1						: 标志字节
	* sizeof(int)			: size字段
	* sizeof(ulong)*size	: keys数组
	* sizeof(int)			: branchs字段
	*
	* nodes数组字段不记录，DFS序列化树和反序列化
	* 故节点在文件中位置标示了连接关系
	*/
	char* serialize(int&);
	bool load(char*);
};

#endif // !BP_INNER_NODE_H

